package com.woniuxy.springbootrabbit.controller;

import com.woniuxy.springbootrabbit.dead.DeadProducter;
import com.woniuxy.springbootrabbit.delay.DelayProducter;
import com.woniuxy.springbootrabbit.direct.DirectProducter;
import com.woniuxy.springbootrabbit.publish.PublishProducter;
import com.woniuxy.springbootrabbit.simple.Producter;
import com.woniuxy.springbootrabbit.topic.TopicProducter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/rabbit")
public class RabbitController {
    @Resource
    private PublishProducter publishProducter;

    @GetMapping("/start")
    public void start(String msg){
        publishProducter.send(msg);
    }

    /**
     * 路由模式
     */
    @Resource
    private DirectProducter directProducter;

    @GetMapping("/send/{msg}/{route}")
    public void send(@PathVariable("msg") String msg, @PathVariable("route") String route){
        directProducter.send(msg, route);
    }

    /**
     * 主题模式
     */
    @Resource
    private TopicProducter topicProducter;

    @GetMapping("/begin/{msg}/{route}")
    public void begin(@PathVariable("msg") String msg, @PathVariable("route") String route){
        topicProducter.send(msg, route);
    }

    /**
     * 死信（延迟）队列
     */
    @Resource
    private DeadProducter deadProducter;

    @GetMapping("/dead/{msg}/{route}")
    public void dead(@PathVariable("msg") String msg, @PathVariable("route") String route){
        deadProducter.send(msg, route);
    }


    /**
     * 延迟插件
     */
    @Resource
    private DelayProducter delayProducter;

    @GetMapping("/delay/{msg}/{route}/{delay}")
    public void delay(@PathVariable("msg") String msg, @PathVariable("route") String route,@PathVariable("delay") int delay){
        delayProducter.send(msg,route,delay);
    }
}
